package com.ityu.controller;


import com.ityu.pojo.Clazz;
import com.ityu.pojo.pagePojo.ClazzPage;
import com.ityu.pojo.result.Result;
import com.ityu.service.ClazzService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    @Autowired
    ClazzService classService;

    @GetMapping
    public Result pageFindClass(ClazzPage clazzPage) {
        log.info("-----ClazzController-----条件分页查询班级，参数为{}", clazzPage);
        return Result.success( classService.pageFindClazz(clazzPage) );
    }


    @DeleteMapping("/{id}")
    public Result deleteClass(@PathVariable Integer id){
        log.info("-----ClazzController-----删除班级，参数为{}", id);
        classService.deleteClass(id);
        return Result.success();
    }

    @PostMapping
    public Result addClass(@RequestBody Clazz clazz){
        log.info("-----ClazzController-----添加班级，参数为{}", clazz);
        classService.addClass(clazz);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getClassById(@PathVariable Integer id){
        log.info("-----ClazzController-----查询班级，参数为{}", id);
        return Result.success( classService.getClassById(id) );
    }

    @PutMapping
    public Result updateClass(@RequestBody Clazz clazz){
        log.info("-----ClazzController-----修改班级，参数为{}", clazz);
        classService.updateClass(clazz);
        return Result.success();
    }

    @GetMapping("/list")
    public Result listClass(){
        log.info("-----ClazzController-----查询所有班级");
        return Result.success( classService.listClass() );
    }
}
